import html2canvas from 'html2canvas'

const convertToImage = (container, options = {}) => {
  // 设置放大倍数
  const scale = window.devicePixelRatio

  // 传入节点原始宽高
  const width = container.offsetWidth
  const height = container.offsetHeight

  // html2canvas配置项
  const ops = {
    scale,
    width,
    height,
    useCORS: true,
    allowTaint: false,
    ...options
  }

  return html2canvas(container, ops).then(canvas => {
    // 返回图片的二进制数据
    return canvas.toDataURL('image/png')
  })
}

export default convertToImage

// 调用函数，取到截图的二进制数据，对图片进行处理（保存本地、展示等）
// const imgBlobData = await convertToImage(element)
